package chd.edu.spzx.manager.service.impl;

import chd.edu.spzx.manager.mapper.CategoryBrandMapper;
import chd.edu.spzx.manager.service.CategoryBrandService;
import chd.edu.spzx.model.dto.product.CategoryBrandDto;
import chd.edu.spzx.model.entity.product.Brand;
import chd.edu.spzx.model.entity.product.CategoryBrand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Zhang Chaoliang
 * create 2023
 */
@Service
public class CategoryBrandServiceImpl implements CategoryBrandService {

    @Autowired
    private CategoryBrandMapper categoryBrandMapper;

    /**
     * 分类品牌条件分页查询
     * @param page
     * @param limit
     * @param categoryBrandDto
     * @return
     */
    @Override
    public PageInfo findByPage(Integer page, Integer limit, CategoryBrandDto categoryBrandDto) {
        PageHelper.startPage(page,limit);
        List<CategoryBrand> categoryBrandList = categoryBrandMapper.fingByPage(categoryBrandDto);
        PageInfo<CategoryBrand> pageInfo = new PageInfo<>(categoryBrandList);
        return pageInfo;
    }

    /**
     * 分类品牌添加
     * @param categoryBrand
     * @return
     */
    @Override
    public void save(CategoryBrand categoryBrand) {
        categoryBrandMapper.save(categoryBrand);
    }

    /**
     * 分类品牌修改接口
     * @param categoryBrand
     * @return
     */
    @Override
    public void updateById(CategoryBrand categoryBrand) {
        categoryBrandMapper.updateById(categoryBrand);
    }

    /**
     * 分类品牌删除
     * @param id
     * @return
     */
    @Override
    public void deleteById(Long id) {
        categoryBrandMapper.deleteById(id);
    }

    /**
     * 根据分类id查询对应品牌数据
     * @return
     */
    @Override
    public List<Brand> findBrandByCategoryId(Long categoryId) {

        return categoryBrandMapper.findBrandByCategoryId(categoryId);
    }
}
